#include <errno.h>

enum sched_reason {
	SWITCH_REASON_INVALID = -1,
	SWITCH_REASON_CREATE = 1,
	SWITCH_REASON_END = 2,
	SWITCH_REASON_YIELD = 3,
	SWITCH_REASON_MQ_OVERDUE = 4,
	SWITCH_REASON_TO_WAIT = 5,
	SWITCH_REASON_FROM_WAIT = 6,
	SWITCH_REASON_TIMESLICE_END = 7,
};

struct switch_info {
	int previous_pid;
	int next_pid;
	int previous_policy;
	int next_policy;
	unsigned long time;
	enum sched_reason reason;
};

int is_mq(int pid)
{
	long __res;
	__asm__ volatile ("movl $243, %%eax;"
			  "movl %1, %%ebx;"
			  "int $0x80;" "movl %%eax,%0":"=m" (__res)
			  :"m"(pid)
			  :"%eax", "%ebx");
	if ((unsigned long)(__res) >= (unsigned long)(-125)) {
		errno = -(__res);
		__res = -1;
	}
	return (int)(__res);
}

int get_scheduling_statistic(struct switch_info * si)
{
	long __res;
	__asm__ volatile ("movl $244, %%eax;"
			  "movl %1, %%ebx;"
			  "int $0x80;" "movl %%eax,%0":"=m" (__res)
			  :"m"(si)
			  :"%eax", "%ebx");
	if ((unsigned long)(__res) >= (unsigned long)(-125)) {
		errno = -(__res);
		__res = -1;
	}
	return (int)(__res);
}
